﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Xml;
using System.IO;
using UIFramework;

//Sybase:
using FieldServices_01;
using Sybase.Mobile;
using Sybase.Persistence;
using Sybase.Collections;

namespace FieldServices
{
    public partial class frmLogin : UIForm
    {
        public frmLogin()
        {
            InitializeComponent();
            txtUserID.Focus();
            DateTime time = FieldServices_01DB.GetLastSynchronizationTime("default");
            AddString("Lastest Sychronize:" + time.ToString());
            //AddString(time.ToString());
            radSam.Checked = true;
            Common.bchoise = false;

        }

        public void AddString(String s)
        {
            txtStt.Text += s + "\r\n";
            txtStt.SelectionStart = txtStt.Text.Length;
            txtStt.ScrollToCaret();
            txtStt.Refresh();

        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (Common.bchoise == true)
            {
                #region SAP
                try
                {
                    Common.Register(txtStt);
                    Common.login = Common._MboLogin(txtUserID.Text, txtPwd.Text);
                    if (Common.login.E_RETURN != 0)
                    {
                        MessageBox.Show(Common.login.MESSAGE);
                    }
                    else
                    {
                        frmFieldService frm = new frmFieldService();
                        frm.Show();
                    }
                }

                catch (SystemException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                #endregion
            }
            else
            {
                #region Sample
                if (txtUserID.Text == "quynhdm" && txtPwd.Text == "123")
                {
                    frmFieldService frm = new frmFieldService();
                    frm.Show();
                }
                else
                {
                    AddString("Invalid User name/Password");
                }
                #endregion
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.Application.Exit();
        }

        private void frmLogin_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == System.Windows.Forms.Keys.Up))
            {
                // Up
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Down))
            {
                // Down
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Left))
            {
                // Left
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Right))
            {
                // Right
            }
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
            {
                // Enter
            }

        }

        private void radSap_CheckedChanged(object sender, EventArgs e)
        {
            Common.bchoise = true;
        }

        private void radSam_CheckedChanged(object sender, EventArgs e)
        {
            Common.bchoise = false;
        }

    }
}